package ligne2vie.topos.shared.bo;

/**
 * The class {@link CoordinatesHandler} provides a lot of different methods helping to handle coordinates.
 * 
 * @author thuguerre
 * @since 1.1.0
 */
public class CoordinatesHandler {

	/**
	 * The method {@link #latitudeDegreeLength(double)} returns the length of a degree of latitude, in meters, depending
	 * on the latitude it is computed at.
	 * 
	 * @param lat
	 *            Latitude at which is computed the length.
	 * @return Length in meters.
	 * @see http://www.csgnetwork.com/degreelenllavcalc.html
	 */
	public static double latitudeDegreeLength(double lat) {

		double m1 = 111132.92;
		double m2 = -559.82;
		double m3 = 1.175;
		double m4 = -0.0023;

		return (m1 + (m2 * Math.cos(2 * lat)) + (m3 * Math.cos(4 * lat)) + (m4 * Math.cos(6 * lat)));
	}

	/**
	 * The method {@link #longitudeDegreeLength(double)} returns the length of a degree of longitude, in meters,
	 * depending on the latitude it is computed at.
	 * 
	 * @param lat
	 *            Latitude at which is computed the length.
	 * @return Length in meters.
	 * @see http://www.csgnetwork.com/degreelenllavcalc.html
	 */
	public static double longitudeDegreeLength(double lat) {

		double p1 = 111412.84;
		double p2 = -93.5;
		double p3 = 0.118;

		return ((p1 * Math.cos(lat)) + (p2 * Math.cos(3 * lat)) + (p3 * Math.cos(5 * lat)));
	}
}
